<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>交往记录列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/css/public.css" media="all" />
</head>
<body class="childrenBody">

<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
               <!-- <div class="layui-input-inline">
                    <input type="text" class="layui-input searchVal" placeholder="请输入搜索的内容" />
                </div>
                <a class="layui-btn search_btn" data-type="reload">搜索</a>-->
            </div>
            <div class="layui-inline">
                <a class="layui-btn layui-btn-normal addCommunication_btn">添加活动记录</a>
            </div>
            <div class="layui-inline">
                <a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn">批量删除</a>
            </div>
        </form>
    </blockquote>
    <table id="communicationList" lay-filter="communicationList">
        <input type="hidden" id="custNo" class="custNo" name="custNo"></input>
    </table>

    <!--操作-->
    <script type="text/html" id="communicationListBar">
        <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="look">预览</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
    </script>
</form>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
        var communicationno=$("#custNo").val();

        //联系人列表
        var tableIns = table.render({
            elem: '#communicationList',
            url:"communications/selectLinkman",
            page : false,
            id : "communicationListTable",
            where:{
                commCustNo:communicationno
            },
            cols : [[
                {type: "checkbox", fixed:"left"},
                {field: 'customer', title: '公司名称',align:"center",templet:function (row) {
                        return row.customer.custName;
                    }},
                /*{field: 'commNo', title: '活动记录编号',align:"center"},*/
                {field: 'commCustNo', title: '客户编号',align:"center"},
                {field: 'commDate', title: '活动时间', align:"center"},
                {field: 'commAddress', title: '活动地点',align:"center"},
                {field: 'commTitle', title: '活动概要',align:"center"},
                {field: 'commDetail', title: '活动详细信息', align:"center"},
                {field: 'commRemark', title: '备注', align:"center"},
                {field: 'commFlag', title: '活动记录标识',align:"center",templet:function (row) {
                        return row.commFlag==1?"启用":"禁用";
                    }},
                {title: '操作', width:250, templet:'#communicationListBar',fixed:"right",align:"center"}
            ]]
        });

        table.on("tool(communicationList)",function (obj) {
            //获取当前行的数据
            var data=obj.data;
            switch (obj.event){
                case 'del':
                    deleteCommunication(data);
                    break;
                case 'edit':
                    editCommunicationList(data);
                    break;
                case 'look':
                    lookCommunicationList(data);
                    break;
            }
        });

        //单击添加联系人按钮
        $(".addCommunication_btn").click(function () {
            var index=layui.layer.open({
                title:"添加交往记录",
                type:2,
                content:"toCommunicationAddPage.do",
                success : function(layero, index){
                     var body = layui.layer.getChildFrame('body', index);
                    body.contents().find(".commCustNo").val(communicationno);
                }
            });
            //全屏打开窗口
            layui.layer.full(index);
            window.sessionStorage.setItem("index",index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize",function(){
                layui.layer.full(window.sessionStorage.getItem("index"));
            })
        });

        //预览界面
        function lookCommunicationList(data){
            var index=layui.layer.open({
                title:"预览活动详情",
                type:2,
                content:"toCommunicationViewPage.do",
                success:function (layero,index) {
                    var body = layui.layer.getChildFrame('body', index);//少了这个是不能从父页面向子页面传值的
                    body.contents().find(".commNo").val(data.commNo);
                    body.contents().find(".commCustNo").val(data.commCustNo);
                    body.contents().find(".commDate").val(data.commDate);
                    body.contents().find(".commAddress").val(data.commAddress);
                    body.contents().find(".commTitle").val(data.commTitle);
                    body.contents().find(".commDetail").val(data.commDetail);
                    body.contents().find(".commRemark").val(data.commRemark);
                    if(data.commFlag==1){
                        body.contents().find("input[type='radio']").eq(0).attr("checked",true);
                    }else if(data.commFlag==0){
                        body.contents().find("input[type='radio']").eq(1).attr("checked",true);
                    }
                }
            });
            layui.layer.full(index);//全屏显示
        }




        //进入交往记录的编辑页面
        function editCommunicationList(data){
            var index=layui.layer.open({
                title:"编辑交往",
                type:2,
                content:"toCommunicationEidtPage.do",
                success:function (layero,index) {
                    var body = layui.layer.getChildFrame('body', index);//少了这个是不能从父页面向子页面传值的
                    body.contents().find(".commNo").val(data.commNo);
                    body.contents().find(".commCustNo").val(data.commCustNo);
                    body.contents().find(".commDate").val(data.commDate);
                    body.contents().find(".commAddress").val(data.commAddress);
                    body.contents().find(".commTitle").val(data.commTitle);
                    body.contents().find(".commDetail").val(data.commDetail);
                    body.contents().find(".commRemark").val(data.commRemark);
                    if(data.commFlag==1){
                        body.contents().find("input[type='radio']").eq(0).attr("checked",true);
                    }else if(data.commFlag==0){
                        body.contents().find("input[type='radio']").eq(1).attr("checked",true);
                    }
                }
            });
            layui.layer.full(index);//全屏显示
        }


        function deleteCommunication(data){
            $.ajax({
                url:"communications/"+data.commNo,
                type:"DELETE",
                dataType:"json",
                success:function (res) {
                    if(res.code==1000){
                        layer.msg(res.msg);
                        tableIns.reload();//重新刷新表格
                    }
                }
            });
        }
        //完成批量删除
        //批量删除
        $(".delAll_btn").click(function () {

            var checkStatus = table.checkStatus('communicationListTable');
            var data = checkStatus.data;
            var ccommNos = [];
            if(data.length > 0) {
                for (var i in data) {
                    ccommNos.push(data[i].commNo);
                }
                layer.confirm('确定删除选中的记录？', {icon: 3, title: '提示信息'}, function (index) {
                    /*
                    $.get("/sys/deleteBatchUser.html",{ids:uIds},function (res) {
                        tableIns.reload();
                        layer.close(index);
                    });
                    */
                    $.ajax({
                        url:"communications/deleteBatch",
                        type:"GET",
                        data:{commNos:ccommNos},
                        dataType:"json",
                        success:function (res) {
                            if(res.code==1000){
                                tableIns.reload();
                                layer.close(index);
                            }
                        }
                    });
                })
            }else{
                layer.msg("请选择需要删除的记录");
            }
        });







    })

</script>
</body>
</html>